﻿package mortal.game.view.copy.sunbathCopy.view
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.copy.sunbathCopy.render.*;
    import mortal.game.view.guildNew.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class SunbathCopyEnterView extends SpecialWindow
    {
        private var _list:GTileList;
        private var _pageSelecter:PageSelecter;
        private var _pageTool:PageTool;
        private var _vipTip:VipOpenTipsPanel;
        private static var _instance:SunbathCopyEnterView;

        public function SunbathCopyEnterView()
        {
            this._pageTool = new PageTool([], 8);
            setSize(580, 450);
            return;
        }// end function

        override protected function updateBtnSize() : void
        {
            if (_closeBtn)
            {
                _closeBtn.x = this.width - _closeBtn.width - 15;
                _closeBtn.y = 8;
            }
            return;
        }// end function

        private function onSunbathInfoRes(param1:Object) : void
        {
            this._pageTool.array = Cache.instance.copy.sunbath.sunBaths;
            this._pageSelecter.maxPage = this._pageTool.pagesCount;
            this._pageSelecter.currentPage = 1;
            this.onListPageChange();
            return;
        }// end function

        private function onListPageChange(event:Event = null) : void
        {
            this._list.dataProvider = new DataProvider(this._pageTool.getByPageNo(this._pageSelecter.currentPage));
            this._list.drawNow();
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            Dispatcher.dispatchEvent(new DataEvent(EventName.SunbathInfoReq));
            return;
        }// end function

        private function onResCompl() : void
        {
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SunbathCopyEnterViewTitle, 0, 0, this));
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SunbathCopyEnterViewBg, 4, 35, this));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(70967) + ActionTimeShowUtil.instance.SunbatchStr, 375, 416, 200, 20, this, GlobalStyle.textFormatLv.right()));
            this._list = UIFactory.tileList(12, 128, 590, 280, this);
            this._list.setStyle("cellRenderer", SunbathCopyEnterViewRenderer);
            this._list.columnWidth = 143;
            this._list.rowHeight = 135;
            this._list.direction = GBoxDirection.VERTICAL;
            this._pageSelecter = UIFactory.pageSelecter(225, 413, this, PageSelecter.CompleteMode);
            this._pageSelecter.configEventListener(Event.CHANGE, this.onListPageChange);
            this._vipTip = UIFactory.getUICompoment(VipOpenTipsPanel, 309, 93, this);
            this._vipTip.valueType = VipOpenTipsPanel.percentValue;
            this._vipTip.resetLevelTextPos(46, 9, 46, 9);
            this._vipTip.resetValueTextPos(236, 9, 236, 9);
            this._vipTip.bgUrl = ImagesConst.vipOpenTipsBg_mid;
            this._vipTip.vipType = EVipRecordType._EVipRecordTypeBeachExp;
            pushUIToDisposeVec(this._vipTip);
            _closeBtn.parent.addChild(_closeBtn);
            NetDispatcher.addCmdListener(ServerCommand.SunbathInfoRes, this.onSunbathInfoRes);
            LoaderHelp.addResCallBack(ResFileConst.sunbathCopy, this.onResCompl);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._list.dispose(param1);
            this._pageSelecter.dispose(param1);
            this._list = null;
            this._pageSelecter = null;
            NetDispatcher.removeCmdListener(ServerCommand.SunbathInfoRes, this.onSunbathInfoRes);
            LoaderHelp.removeResEvent(ResFileConst.sunbathCopy, this.onResCompl);
            return;
        }// end function

        public static function get instance() : SunbathCopyEnterView
        {
            if (_instance == null)
            {
                _instance = new SunbathCopyEnterView;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
